dim doc
set doc = application.activedocument
doc.unit = 4

dim v
Set v = doc.ActiveView 
dim dx
dx = 0.25

dim xc,yc
dim isSet,isDrawShape
isSet = false
isDrawShape = true

dim x1,x2,y1,y2

dim curlyr
dim unit_str
unit_str = "mm"

Application.ModelessCmd("g0")
Application.ModelessCmd("gd0")
Application.StatusBarText = "Set Grids = 0"
	

dim lyrname,ostr,tmpfile
tmpfile = doc.path & "\tmp1.mcr"
Dim fso,fw
Set fso = CreateObject("scripting.filesystemobject")

Set selected = doc.GetObjects(4, ,TRUE) 
if selected.count = 1 then
	For Each ob In selected 	
		xc = ob.PositionX
		yc = ob.PositionY
		x1 = xc
		x2 = xc+dx
		y1 = yc
		y2 = yc+dx
		for i=1 to doc.ElectricalLayerCount
			application.modelesscmd("l " & i)		
			lyrname = doc.LayerName(doc.activelayer)
			ostr=""
			ostr = ostr & "Application.HideBar(""Design Toolbar"")" & chr(13) & chr(10)
			ostr = ostr & "Application.ShowBar(""Drafting Toolbar"")" & chr(13) & chr(10)
			ostr = ostr & "Application.ExecuteCommand(""Add Keepout Polyline"")" & chr(13) & chr(10)
			ostr = ostr & "Application.ExecuteCommand(""Drafting Circle Mode"")" & chr(13) & chr(10)
			ostr = ostr & "Application.ExecuteCommand(""Down"", " & x1 & unit_str & ", " & y1 & unit_str & ")" & chr(13) & chr(10)
			ostr = ostr & "Application.ExecuteCommand(""Select"", " & x1 & unit_str & ", " & y1 & unit_str & ")" & chr(13) & chr(10)
			ostr = ostr & "Application.ExecuteCommand(""Add Corner To Drafting"", " & x1 & unit_str & ", " & y1 & unit_str & ") "& chr(13) & chr(10)
			ostr = ostr & "Application.ExecuteCommand(""Add Corner To Drafting"", " & x2 & unit_str & ", " & y2 & unit_str & ") "& chr(13) & chr(10)
			if application.version=9.5 then
				ostr = ostr & "DraftingPropertiesDlg.CopperPourAndPlaneArea = true" & chr(13) & chr(10)
			else
				ostr = ostr & "DraftingPropertiesDlg.CopperPlane = true" & chr(13) & chr(10)
			end if
			ostr = ostr & "DraftingPropertiesDlg.LayerName = """ & lyrname & """" & chr(13) & chr(10)
			ostr = ostr & "DraftingPropertiesDlg.Ok.Click()" & chr(13) & chr(10)
			ostr = ostr & "Application.ExecuteCommand(""Complete Drafting"")" & chr(13) & chr(10)

			
			Set fw = fso.CreateTextFile(tmpfile,True)
			fw.Write ostr
			fw.close
					
			application.RunMacro(tmpfile,"")
			Application.ExecuteCommand("Complete Drafting")
			Application.ExecuteCommand("Cancel")
		next
	Next ob	

	Set fw = Nothing	
	Set fso = Nothing	

	Application.ModelessCmd("g " & doc.gridx)
	Application.ModelessCmd("gd " & doc.gridx)
	Application.StatusBarText = "Set Grids = " & doc.gridx

	'reset to select vias
	Application.ExecuteCommand("Filter")
	SelectionFilterDlg.Nothing.Click()
	SelectionFilterDlg.SelectionObjectsDlg.Vias = true
	SelectionFilterDlg.SelectionObjectsDlg.StitchingVias = true
	SelectionFilterDlg.Ok.Click()
	Application.StatusBarText = "Select Vias"
	dim ws : set ws = CreateObject("WScript.Shell")
	ws.RegWrite "HKEY_CURRENT_USER\Software\MyApp\PADS\ApplicationMode", 1, "REG_EXPAND_SZ"
	set ws = nothing
else
	Application.StatusBarText = "Please select only one via!"
end if


		
		


